<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>030-用Promise处理Ajax.html</title>
</head>
<body>
	
</body>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
	//1.需要一个生成promise的函数
	const getDataPromise = (url,type='get',data='')=>new Promise((resolve,reject)=>{
		//处理异步请求(ajax)
		$.ajax({
			url:url,
			type:type,
			data:data,
			success:(data)=>{
				resolve(data)
			},
			error:(jqXhr,statusMsg)=>{
				reject(statusMsg)
			}
		})
	})

	//用函数生成promise
	getDataPromise('https://api.github.com/users/kuazhu')
	.then(data=>{
		// console.log(data)
		return getDataPromise(data.followers_url)
	})
	.then(data=>{
		return getDataPromise(data[0].followers_url)
	})
	.then(data=>{
		console.log(data)
	})
	.catch(err=>{
		console.log(err)
	})
</script>
</html>